home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / DOS32V33.ZIP / EXAMPLES / RMTABS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-15  |  1.6 KB  |  76 lines

  1. /***************************************************************************
  2.     RMTABS.C        Small file utility for replacing the tab characters with
  3.                     space characters.
  4.  
  5.     Written by Adam Seychell
  6.  
  7.  Building example using BCC32.
  8.  
  9.  bcc32 -c rmtabs.c
  10.  dlink -c rmtabs.obj c0.obj ,,, pal.lib
  11.  
  12.  
  13.  Building example using GCC.
  14.  
  15.  gcc -c -v rmtabs.c
  16.  dlink -c rmtabs.o c0.obj ,,, pal.lib
  17.  
  18.  
  19.  Possible building example using WATCOM
  20.  
  21.  wcc -c rmtabs.c
  22.  dlink -c rmtabs.obj c0.obj ,,, pal.lib
  23.  
  24. ***************************************************************************/
  25. #include <stdio.h>
  26.  
  27. char usage_mesg[]={ \
  28. "Replces tab characters with spaces\n\
  29. \n\
  30.     Usage:  rmtabs <file> <tab size>\n\
  31. "};
  32.  
  33. FILE * fptr;
  34. int c,tabsize;
  35.  
  36. void error(char * msg)
  37. {
  38. fprintf(stderr,msg);
  39.  exit(0);
  40. }
  41.  
  42. int main(int argc, char * argv[])
  43. {
  44. int position;
  45. int i;
  46.  
  47.  if (argc != 3 ) error((char*)&usage_mesg);
  48.  tabsize=atoi(argv[2]);
  49.  if (tabsize == 0) error("tab size must be an integer above zero\n");
  50.  
  51.  fptr=fopen(argv[1],"r");
  52.  if (fptr == 0 ) error("file open error\n");
  53.  position=0;
  54.  for (; ; ) {
  55.  
  56.      if ( (c=fgetc(fptr)) == EOF) break;
  57.      if (c==9) {
  58.         i=tabsize - (position%tabsize);
  59.         position+=i;
  60.         for ( ; i > 0 ; i--) {
  61.             if ( fputc(' ',stdout) == EOF) error("file output error\n");
  62.         }
  63.      }
  64.      else
  65.      {
  66.         if ( putchar(c) == EOF) error("file output error\n");
  67.         if (c!=13) position++;
  68.      }
  69.      if (c==10) position=0;
  70.  
  71. }
  72.      fclose(fptr);
  73.  
  74. return 0;
  75. }
  76.